function createGetter() {
    return function (target, key, receiver) {
        //依赖收集
        // console.log(needTrack);
        if (needTrack) track(target, key, receiver);
        return Reflect.get(target, key, receiver);
    }
}
function createSetter() {
    return function (target, key, value, receiver) {
        Reflect.set(target, key, value, receiver);
        //派发更新当前key的依赖
        let depsMap = targetMap.get(target);
        if (depsMap) trigger(target, key, depsMap.get(key))
    }
}
const targetMap = new WeakMap()
function track(target, key, receiver) {
    // console.log(target, key, receiver, "track");
    // return
    //获取target的依赖deps=>map
    let depsMap = targetMap.get(target);
    if (!depsMap) targetMap.set(target, (depsMap = new Map()))
    //依赖收集
    let deps = depsMap.get(key)
    if (!deps) depsMap.set(key, (deps = new Set()))
    //添加当前targe对应key的依赖函数
    if (currentEffect) deps.add(currentEffect)
}
let currentEffect = undefined;
//派发更新
function trigger(target, key, deps) {
    deps.forEach(effect => {
        effect.run(target, key);
    });
}

// function effect(fn, ...args) {
//     currentEffect = fn
//     fn(...args)
//     currentEffect = undefined
// }
//依赖副作用函数类
class ReactiveEffect {
    constructor(fn) {
        this._fn = fn
        this.run()
    }
    run() {
        currentEffect = this
        this._fn()
    }
}
//统一调用依赖函数
function effect(fn) {
    currentEffect = new ReactiveEffect(fn)
}
// 是否响应式
function isReactive(value) {
    return typeof value === "object" && value !== null && value.isReactive
}